/**
 * 
 */
package com.celephais.common.server.model;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

/**
 * @author Eugene Shen
 * Interface that all stand-alone persistent objects must implement if they
 * want to use our generic services.  As of this writing, the only
 * @PersistenceCapable classes exempt from this are @EmbeddedOnly classes. 
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
// Makes sure fields will be stored in subclasses' tables.
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class PersistentObject {
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	public PersistentObject() {
		super();
	}
	
	public PersistentObject(Key key) {
		this();
		setKey(key);
	}
	
	public Key getKey() {
		return key;
	}
	public void setKey(Key key) {
		this.key = key;
	}
	
	/**
	 * Return a human-readable name that represents an instance of this object.
	 * Ideally, this should be unique, but that is not required.
	 * @return A human-readable name to identify an instance of this object.
	 */
	public abstract String getName();
	
}
